package com.ikkong.system.util;

import com.ikkong.core.dao.Blade;
import com.ikkong.core.jfinal.ext.shiro.ShiroKit;
import com.ikkong.school.model.Suppliers;

import java.util.*;


public class CommonUtil {

	public static int getSuppid(){
        String string = ShiroKit.getUser().getDeptId().toString();
        Suppliers suppliers = Blade.create(Suppliers.class).findFirstBy("d_id = " + string, Suppliers.class);
        int i = 0;
        if(suppliers!= null){
            i = suppliers.getId();
        }
        return i;
    }

	public static Object fenye(List maps,int page,int rows){
		int start = (page-1)*rows;
		double d = maps.size()*1.00/rows*1.00;
		int end = start + rows;
		if (end>maps.size()){
			end = maps.size();
		}
		List<Map> newmap = maps.subList(start,end);
		Map sss = new HashMap();
		sss.put("rows",newmap);
		sss.put("total",Math.ceil(d));
		sss.put("page",page);
		sss.put("records",maps.size());
		Object o = sss;
		return o;
	}

	public static void createFieldNameList(List<Map<String, Object>> fieldNameList, String index, String width, String textAlign, String onRenderEvent, boolean isHidden) {
		Map<String, Object> fieldNameMap = new HashMap<String, Object>();
		fieldNameMap.put("index", index);
		fieldNameMap.put("width", width);
		fieldNameMap.put("textAlign", textAlign);
		fieldNameMap.put("isHidden", isHidden);
		fieldNameMap.put("onRenderEvent", onRenderEvent);
		fieldNameMap.put("isSort", true);
		fieldNameList.add(fieldNameMap);
	}
	public static boolean ynadmin(){
        List<String> roleList = ShiroKit.getUser().getRoleList();
        boolean b = false;
        for(String ss:roleList){
            if("1".equals(ss) || "2".equals(ss)){
                b = true;
                break;
            }
        }
        return b;
    }

	public static boolean ynleader(){
		List<String> roleList = ShiroKit.getUser().getRoleList();
		boolean b = false;
		for(String ss:roleList){
			if("1".equals(ss) ||"2".equals(ss) ||"8".equals(ss) ||"9".equals(ss) ||"13".equals(ss)  ){
				b = true;
				break;
			}
		}
		return b;
	}

	public static boolean yncaiwu(){
		List<String> roleList = ShiroKit.getUser().getRoleList();
		boolean b = false;
		for(String ss:roleList){
			if("1".equals(ss) ||"2".equals(ss) ||"8".equals(ss) ||"9".equals(ss) ||"11".equals(ss) ||"12".equals(ss) ||"13".equals(ss)  ){
				b = true;
				break;
			}
		}
		return b;
	}
	public static boolean ynsuper(){
		List<String> roleList = ShiroKit.getUser().getRoleList();
		boolean b = false;
		for(String ss:roleList){
			if("1".equals(ss)){
				b = true;
				break;
			}
		}
		return b;
	}
	public static String quchong(String s){

		String[] array = s.split(",");
		Set<String> set = new HashSet<>();
		for(int i=0;i<array.length;i++){
			set.add(array[i]);
		}
		String[] arrayResult = (String[]) set.toArray(new String[set.size()]);
		return Arrays.toString(arrayResult);
	}
	public static void createEditFieldNameList(List<Map<String, Object>> fieldNameList, String index, String width, String textAlign, String onRenderEvent, boolean isHidden) {
		Map<String, Object> fieldNameMap = new HashMap<String, Object>();
		fieldNameMap.put("index", index);
		fieldNameMap.put("width", width);
		fieldNameMap.put("textAlign", textAlign);
		fieldNameMap.put("isHidden", isHidden);
		fieldNameMap.put("onRenderEvent", onRenderEvent);
		fieldNameMap.put("isSort", true);
		fieldNameMap.put("isEdit", true);
		fieldNameList.add(fieldNameMap);
	}

	public static void createFieldNameList(List<Map<String, Object>> fieldNameList, String index, String width, String textAlign, String onRenderEvent, boolean isHidden, boolean isSort) {
		Map<String, Object> fieldNameMap = new HashMap<String, Object>();
		fieldNameMap.put("index", index);
		fieldNameMap.put("width", width);
		fieldNameMap.put("textAlign", textAlign);
		fieldNameMap.put("isHidden", isHidden);
		fieldNameMap.put("onRenderEvent", onRenderEvent);
		fieldNameMap.put("isSort", isSort);
		fieldNameList.add(fieldNameMap);
	}

}
